<?php
/**
 * 金额导入模型
 * @author jianhui
 * 
 *
 */
class importMoneyModel extends MY_Model{
    var $typeCon = array(
        11 => '单店基金双月额度',
        12 => '单店基金天网行动双月额度',
        13 => '单店双月来店目标',
        14 => '单店基金来店实际',
        15 => '单店基金标准动作完成率',
        21 => '城市提升基金双月额度',
        22 => '城市提升基金结算金额',
        31 => '车展基金广宣活动补贴',
        32 => '车展基金启辰店实际出资总额',
        33 => '车展基金配套额度',
        34 => '车展基金本站结算金额',
        35 => '车展基金KPI系数',
        51 => '固定传播基金年度额度',
        52 => '固定传播基金双月扣罚金额',
        61 => '专项单店基金双月额度',
        71 => '专项城市基金双月额度',
    );
    function importMoneyModel(){
        parent::MY_Model();
        $this->table = 'ImportMoney';
    }
    /**
     * 包装数据(non-PHPdoc)
     * @see MY_Model::packing()
     */
    function packing($list = array()){
        //时间单位配置
        $this->CI->load->model('timeUnitModel');
        $timeUnitList = $this->CI->timeUnitModel->getCacheData('timeUnitList');
        foreach ($list as $k => $v){
            $list[$k]['typeStr'] = isset($this->typeCon[$v['type']]) ? $this->typeCon[$v['type']] : '';
            //时间单位
            $list[$k]['timeUnitStr'] = isset($timeUnitList[$v['year']][$v['timeUnit']]) ? $timeUnitList[$v['year']][$v['timeUnit']] : '';
        }
        return $list;
    }
    /**
     * 获取类型名称
     * @param number $type
     */
    function getTypeName($type){
        return isset($this->typeCon[$type]) ? $this->typeCon[$type] : '';
    }
    /**
     * 获取指定导入类别金额
     * @param int $storeId 店铺用户ID
     * @param int $timeUnit 时间单位
     * @param int $type 金额类别
     * @param number $year 年份
     * @return number
     */
    function getMoney($storeId, $timeUnit, $type , $year = 2015){
        $findData = $this->getData(array('storeId'=>$storeId, 'timeUnit'=>$timeUnit, 'year'=>$year, 'type'=>$type));
        return isset($findData) && $findData['money'] ? (float)$findData['money'] : 0;
    }
    /**
     * 获取指定类型的金额列表并以专营店ID为键
     * @param number $type
     * @param number $year
     * @param nubmer $timeUnit
     * @return array
     */
    function getMoneyListByStoreId($type, $year = 0, $timeUnit = 0){
        //如果不设置年份默认为当前配置年份
        $year || $year = $this->config->item('nowYear');
        $list = $this->getList(array('type'=>$type,'year'=>$year,'timeUnit'=>$timeUnit));
        $moneyList = array();
        foreach ($list as $v){
            isset($moneyList[(int)$v['storeId']]) || $moneyList[(int)$v['storeId']] = $v['money'];
        }
        return $moneyList;
    }
    /**
     * 获取指定专营店集的指定类型金额集
     * @param number $type
     * @param array $storeIds
     * @param number $year
     * @param number $timeUnit
     * @return array
     */
    function getStoresMoney($type, $storeIds = array(), $year = 0, $timeUnit = 0){
        //如果不设置年份默认为当前配置年份
        $year || $year = $this->config->item('nowYear');
        $list = $this->getList(array('type'=>$type,'year'=>$year,'timeUnit'=>$timeUnit));
        $moneyList = array();
        foreach ($list as $v){
            isset($moneyList[(int)$v['storeId']]) || $moneyList[(int)$v['storeId']] = $v['money'];
        }
        return $moneyList;
    }
}